<!DOCTYPE html>
<html lang="zh-cmn-Hans">
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<title>HTML5页面直接调用百度地图API,获取当前位置，直接导航目的地</title>
	<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=i9qaQ2CYBhx4Mlb7cZKheHveOyavpZzm"></script>
	<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
	<!--调用jQuery-->

	<head>
	<style type="text/css">
		body,
		html,
		#allmap {
			width: 100%;
			height: 100%;
			overflow: hidden;
			margin: 0;
			font-family: "微软雅黑";
		}
	</style>

	</head>

	<body>
		<div id="allmap"></div>
	</body>
</html>
<script type="text/javascript">
	var map = new BMap.Map("allmap"); //创建map实例
	var point = new BMap.Point(118.185216, 24.508017); //初始化
	map.centerAndZoom(point, 20);
	map.enableScrollWheelZoom();



	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r) {
		if (this.getStatus() == BMAP_STATUS_SUCCESS) {
			var mk = new BMap.Marker(r.point);
			
			map.addOverlay(mk);
			map.panTo(r.point); //地图中心点移到当前位置 
			var latCurrent = r.point.lat;
			var lngCurrent = r.point.lng;
			alert('我的位置：' + latCurrent + ',' + lngCurrent);

			location.href = "http://api.map.baidu.com/direction?origin=" + latCurrent + "," + lngCurrent +
				"&destination=24.508017,118.185216&mode=driving&region=厦门&output=html";

		} else {
			alert('failed' + this.getStatus());
		}
	}, {
		enableHighAccuracy: true
	})
	
	



	var myIcon = new BMap.Icon("logo11.png", new BMap.Size(30, 30), {
		anchor: new BMap.Size(10, 10)
	});
	
	var marker = new BMap.Marker(point, {
		icon: myIcon
	});


	map.addOverlay(marker);
	var licontent = "<b>爆米花票务</b><br>";
	licontent += "<span><strong>地址：</strong>厦门市湖里区万达广场</span><br>";
	licontent += "<span><strong>电话：</strong>18606905652</span><br>";
	var opts = {
		width: 300,
		height: 100,
	};
	var infoWindow = new BMap.InfoWindow(licontent, opts);
	marker.openInfoWindow(infoWindow);
	marker.addEventListener('click', function() {
		marker.openInfoWindow(infoWindow);
	});
</script>
